 /**
   * Copyright 2014 Viettel Telecom. All rights reserved.
   * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
   */
 package com.viettel.core.dao.cms; 
import java.util.ArrayList; 
import java.util.List; 

import org.hibernate.type.StandardBasicTypes; 
import org.hibernate.type.Type; 
import org.springframework.beans.factory.annotation.Autowired; 

import com.viettel.core.exceptions.DataAccessException; 
import com.viettel.core.entities.cms.Media;
import com.viettel.core.entities.cms.MediaArticle;
import com.viettel.core.enumtype.MediaStatus;
import com.viettel.core.repo.IRepository;
 /**
   *  Mo ta muc dich cua lop (interface)
   *  @author: TOANTM1
   *  @version:  
   *  @since: 27/02/2014 - 11:34:02
   */
 public class MediaArticleDAOImpl implements MediaArticleDAO { 
	 private IRepository repo; 
		
	 	public void setRepo(IRepository repo) {
			this.repo = repo;
		} 
 
 	/**@author TOANTM1
  	 * 27/02/2014 - 11:34:02
  	 * For: 
  	 * @description: 
  	 */
 	@Override 
	public MediaArticle getMediaArticleById(Integer id) throws DataAccessException { 
		return repo.getEntityById(MediaArticle.class, id); 
	} 
 
 	/**@author TOANTM1
  	 * 27/02/2014 - 11:34:02
  	 * For: 
  	 * @description: 
  	 */
 	@Override 
	public MediaArticle createMediaArticle(MediaArticle mediaarticle) 
			throws DataAccessException { 
		if (mediaarticle == null) { 
			throw new IllegalArgumentException("mediaarticle"); 
		} 
		repo.create(mediaarticle); 
		return repo.getEntityById(MediaArticle.class, mediaarticle.getId()); 
	} 
 
 	/**@author TOANTM1
  	 * 27/02/2014 - 11:34:02
  	 * For: 
  	 * @description: 
  	 */
 	@Override 
	public void updateMediaArticle(MediaArticle mediaarticle) throws DataAccessException { 
		if (mediaarticle == null) { 
			throw new IllegalArgumentException("mediaarticle"); 
		} 
		repo.update(mediaarticle); 
	} 
 
 	/**@author TOANTM1
  	 * 27/02/2014 - 11:34:02
  	 * For: 
  	 * @description: 
  	 */
 	@Override 
	public void deleteMediaArticle(MediaArticle mediaarticle) throws DataAccessException { 
		if (mediaarticle == null) { 
			throw new IllegalArgumentException("mediaarticle"); 
		} 
		repo.delete(mediaarticle); 
	} 
 	@Override
	public List<MediaArticle> getListMediaArticlesByCmsUserId(Integer id) throws DataAccessException{
		List<Object> params = new ArrayList<Object>();
		String sql = "SELECT * FROM MEDIA_ARTICLE  where STATUS != ? AND CMS_USER_ID = ?";
		params.add(MediaStatus.DELETED.getValue());
		params.add(id);
		return repo.getListBySQL(MediaArticle.class, sql, params);
	}
} 
 
